<script>
import { defineComponent } from "vue";
import * as echarts from "echarts";

export default defineComponent({
    methods: {
        init() {
            // 绘制图表
            this.myChart1.setOption({
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        crossStyle: {
                            color: '#999'
                        }
                    }
                },
                toolbox: {
                    feature: {
                        dataView: { show: true, readOnly: false },
                        magicType: { show: true, type: ['line', 'bar'] },
                        restore: { show: true },
                        saveAsImage: { show: true }
                    }
                },
                legend: {
                    data: ['Evaporation', 'Precipitation', 'Temperature']
                },
                xAxis: [
                    {
                        type: 'category',
                        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
                        axisPointer: {
                            type: 'shadow'
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name: 'Precipitation',
                        min: 0,
                        max: 250,
                        interval: 50,
                        axisLabel: {
                            formatter: '{value} ml'
                        }
                    },
                    {
                        type: 'value',
                        name: 'Temperature',
                        min: 0,
                        max: 25,
                        interval: 5,
                        axisLabel: {
                            formatter: '{value} °C'
                        }
                    }
                ],
                series: [
                    {
                        name: 'Evaporation',
                        type: 'bar',
                        tooltip: {
                            valueFormatter: function (value) {
                                return value + ' ml';
                            }
                        },
                        data: [
                            2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3
                        ]
                    },
                    {
                        name: 'Precipitation',
                        type: 'bar',
                        tooltip: {
                            valueFormatter: function (value) {
                                return value + ' ml';
                            }
                        },
                        data: [
                            2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3
                        ]
                    },
                    {
                        name: 'Temperature',
                        type: 'line',
                        yAxisIndex: 1,
                        tooltip: {
                            valueFormatter: function (value) {
                                return value + ' °C';
                            }
                        },
                        data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
                    }
                ]
            });
        },
        init2() {
            // 绘制图表
            this.myChart2.setOption({
                xAxis: {
                    type: 'category',
                    boundaryGap: false
                },
                yAxis: {
                    type: 'value',
                    boundaryGap: [0, '30%']
                },
                visualMap: {
                    type: 'piecewise',
                    show: false,
                    dimension: 0,
                    seriesIndex: 0,
                    pieces: [
                        {
                            gt: 1,
                            lt: 3,
                            color: 'rgba(0, 0, 180, 0.4)'
                        },
                        {
                            gt: 5,
                            lt: 7,
                            color: 'rgba(0, 0, 180, 0.4)'
                        }
                    ]
                },
                series: [
                    {
                        type: 'line',
                        smooth: 0.6,
                        symbol: 'none',
                        lineStyle: {
                            color: '#5470C6',
                            width: 5
                        },
                        markLine: {
                            symbol: ['none', 'none'],
                            label: { show: false },
                            data: [{ xAxis: 1 }, { xAxis: 3 }, { xAxis: 5 }, { xAxis: 7 }]
                        },
                        areaStyle: {},
                        data: [
                            ['2019-10-10', 200],
                            ['2019-10-11', 560],
                            ['2019-10-12', 750],
                            ['2019-10-13', 580],
                            ['2019-10-14', 250],
                            ['2019-10-15', 300],
                            ['2019-10-16', 450],
                            ['2019-10-17', 300],
                            ['2019-10-18', 100]
                        ]
                    }
                ]
            });
        },
        init3() {
            // 绘制图表
            this.myChart3.setOption({
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    top: '5%',
                    left: 'center'
                },
                series: [
                    {
                        name: 'Access From',
                        type: 'pie',
                        radius: ['40%', '70%'],
                        avoidLabelOverlap: false,
                        label: {
                            show: false,
                            position: 'center'
                        },
                        emphasis: {
                            label: {
                                show: true,
                                fontSize: 40,
                                fontWeight: 'bold'
                            }
                        },
                        labelLine: {
                            show: false
                        },
                        data: [
                            { value: 1048, name: 'Search Engine' },
                            { value: 735, name: 'Direct' },
                            { value: 580, name: 'Email' },
                            { value: 484, name: 'Union Ads' },
                            { value: 300, name: 'Video Ads' }
                        ]
                    }
                ]
            });
        },
    },
    mounted() {
        // 基于准备好的dom，初始化echarts实例
        this.myChart1 = echarts.init(document.getElementById("main"))
        this.myChart2 = echarts.init(document.getElementById("main1"))
        this.myChart3 = echarts.init(document.getElementById("main2"))
        // 绘制图表
        this.init();
        this.init2();
        this.init3();
    },
});
</script>


<template>
    <div class="div0">
        <div class="div1">
            <h3>用户访问量 <span>今日</span> </h3><br>
            <span>102</span>
            <p class="p0">昨日 377 日环比 -50.5% </p>
            <p class="p1"> 本月访问量 <span>6119Pv</span> </p>
        </div>
        <div class="div2">
            <h3>销售额 <span>今日</span> </h3><br>
            <span>200</span>
            <p class="p0">昨日 0.01 日环比 500% </p>
            <p class="p1"> 本月销售额 <span>61190元</span> </p>
        </div>
        <div class="div3">
            <h3>订单量 <span>今日</span> </h3><br>
            <span>2</span>
            <p class="p0">昨日 1 日环比 50% </p>
            <p class="p1"> 本月订单量 <span>100单</span> </p>
        </div>
        <div class="div4">
            <h3>新增用户 <span>今日</span> </h3><br>
            <span>13</span>
            <p class="p0">昨日 7 日环比 60.5% </p>
            <p class="p1"> 本月新增用户 <span>600</span> </p>
        </div>
    </div>
    <div id="main"></div>
    <div id="main1"></div>
    <div id="main2"></div>
</template>

<style lang="scss" scoped>
* {
    margin: 0;
    padding: 0;
}



.div0 {
    display: flex;
    justify-content: space-around;
    width: 100%;
    height: 160px;
    background-color: rgba($color: #c4c3c3, $alpha: .1);
}

.div1,
.div2,
.div3,
.div4 {
    width: 200px;
    height: 130px;
    padding: 15px;
    background-color: white;

    h3 {
        font-size: 14px;
        position: relative;

        span {
            width: 25px;
            font-size: 12px;
            color: greenyellow;
            display: inline-block;
            border: 1px solid greenyellow;
            position: absolute;
            right: 8px;
            top: 5px;
        }
    }

    span {
        font-size: 25px;
    }

    .p0 {
        color: gray;
        font-size: 14px;
        margin-top: 15px;
        border-bottom: 1px solid black;
    }

    .p1 {
        color: gray;
        font-size: 14px;
        margin-top: 10px;

        span {
            font-size: 12px;
            float: right;
        }
    }
}

#main {
    height: 400px;
    width: 97%;
    margin-top: 40px;
}

#main1 {
    float: left;
    height: 340px;
    width: 60%;
    margin-top: 40px;
}

#main2 {
    float: right;
    height: 340px;
    width: 40%;
}
</style>